Spring + JSR 303 Validation group is ignored [closed]

Posted by nsideras on Programmers See other posts from Programmers or by nsideras
Published on 2012-12-06T11:05:56Z Indexed on 2012/12/06 17:21 UTC
Read the original article Hit count: 256

Filed under:
|

we have a simple bean with JSR annotations

public class CustomerDTO {

    private static final long serialVersionUID = 1L;

    private Integer id;

    @NotEmpty(message = "{customer.firstname.empty}")
    private String firstName;

    @NotEmpty(message = "{customer.lastname.empty}")
    private String lastName;

    @NotEmpty(groups={PasswordChange.class}, message="{password.empty}")
    private String password;

    @NotEmpty(groups={PasswordChange.class}, message="{confirmation.password.empty}")
    private String password2;

}

and we have a Spring Controller

@RequestMapping(value="/changePassword", method = RequestMethod.POST)
public String changePassword(@Validated({ PasswordChange.class }) @ModelAttribute("customerdto") CustomerDTO customerDTO, BindingResult result, Locale locale) {
    logger.debug("Change Password was submitted with information: " + customerDTO.toString());
    try {
        passwordStrengthPolicy.checkPasswordStrength(locale, customerDTO.getPassword());
        if (result.hasErrors()) {
            return "changePassword";
        }
        logger.debug("Calling customer service changePassword: " + customerDTO);
        customerOnlineNewService.changePassword(customerDTO);
    } catch (PasswordNotChangedException e) {
        logger.error("Could not change password PasswordNotChangedException: " + customerDTO.toString());
            return "changePassword";
    } catch (PasswordNotSecureException e) {
        return "changePassword";
    }
    return createRedirectViewPath("changePassword");
}

Our problem is that when changePassword is invoked the validator ignores the group(PasswordChange.class) and validates only firstName and lastName which are not in the group.

Any idea? Thank you very much for your time.

© Programmers or respective owner

Related posts about java

Related posts about spring